package com.example.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutConfig {

    // 定义广播交换机
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanout.exchange");
    }
    @Bean
    public FanoutExchange fanoutObjExchange() {
        return new FanoutExchange("fanout.exchange.obj");
    }

    // 定义第一个队列
    @Bean
    public Queue fanoutQueue1() {
        return new Queue("fanout.queue.1");
    }

    // 定义第二个队列
    @Bean
    public Queue fanoutQueue2() {
        return new Queue("fanout.queue.2");
    }

    // 定义第三个队列
    @Bean
    public Queue fanoutQueue3() {
        return new Queue("fanout.queue.3");
    }

    // 定义第一个队列（用于对象消息）
    @Bean
    public Queue fanoutObjectQueue1() {
        return new Queue("fanout.queue.1.object");
    }

    // 定义第二个队列（用于对象消息）
    @Bean
    public Queue fanoutObjectQueue2() {
        return new Queue("fanout.queue.2.object");
    }

    // 定义第三个队列（用于对象消息）
    @Bean
    public Queue fanoutObjectQueue3() {
        return new Queue("fanout.queue.3.object");
    }

    // 绑定第一个队列到广播交换机
    @Bean
    public Binding binding1() {
        return BindingBuilder.bind(fanoutQueue1()).to(fanoutExchange());
    }

    // 绑定第二个队列到广播交换机
    @Bean
    public Binding binding2() {
        return BindingBuilder.bind(fanoutQueue2()).to(fanoutExchange());
    }

    // 绑定第三个队列到广播交换机
    @Bean
    public Binding binding3() {
        return BindingBuilder.bind(fanoutQueue3()).to(fanoutExchange());
    }

    // 绑定第一个对象队列到广播交换机
    @Bean
    public Binding objectBinding1() {
        return BindingBuilder.bind(fanoutObjectQueue1()).to(fanoutObjExchange());
    }

    // 绑定第二个对象队列到广播交换机
    @Bean
    public Binding objectBinding2() {
        return BindingBuilder.bind(fanoutObjectQueue2()).to(fanoutObjExchange());
    }

    // 绑定第三个对象队列到广播交换机
    @Bean
    public Binding objectBinding3() {
        return BindingBuilder.bind(fanoutObjectQueue3()).to(fanoutObjExchange());
    }
}